home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d3
/
jlp10.arc
/
LETPROC.C
next >
Wrap
C/C++ Source or Header
|
1990-04-08
|
8KB
|
312 lines
char copyright[]=
"Julia's Letter Processor 1.0, Copyright (c) 1990 Michael Deuel Sullivan";
char address[]=
"6011 33rd Street, N.W., Washington, D.C. 20015";
char license[]=
"License granted without charge for non-commercial and educational use.";
/* Command line options:
** L - enable lower case letters (default caps only)
** S - enable symbols (default alphanumeric only)
*/
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <alloc.h>
#include <string.h>
#define MIDDLE_C 256.
#define LEN 200
#define setport(x) setviewport(x.left,x.top,x.right,x.bottom,x.clip)
int scale[]=
{0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36,38,40,41,43};
int song[]=
{0,0,7,7,9,9,7,5,5,4,4,2,2,2,2,0,7,7,5,4,4,2,7,5,4,2};
int len[]=
{2,2,2,2,2,2,4,2,2,2,2,1,1,1,1,4,2,2,4,2,2,4,4,4,2,4};
double freq[44];
char *end_song[]=
{ "NOW ", "I ", "KNOW ", "MY ", "A-", "B-", "C'S",
"NEXT ", "TIME ", "WON'T ", "YOU ", "SING ", "", "WITH ", "", "ME " };
char *lines[5]={
"JULIA'S LETTER PROCESSOR!",
"ABCDEFGHIJKLM",
"NOPQRSTUVWXYZ",
"NOW I KNOW MY A-B-C'S",
"NEXT TIME WON'T YOU SING WITH ME ?"};
double stepmult;
int max_x, max_y;
char caps_only=1;
char alnum_only=1;
void initialize();
void getopts(int argc, char **argv);
void copyright_license();
void intro_song();
void do_letters();
void put_exit_msg();
void twirp();
main (int argc, char **argv) {
initialize();
if (argc>1) getopts(argc,argv);
copyright_license();
intro_song();
cleardevice();
put_exit_msg();
do_letters();
closegraph();
}/* main() */
void initialize () {
int gdriver=DETECT, gmode, g_errorcode;
int i;
for (i=0;i<44;i++) /* sets frequencies for upper half of keyboard */
freq[i]=exp((double)i*log(2.)/12.)*MIDDLE_C;
randomize();
if (registerbgidriver(EGAVGA_driver)<0) {
printf("Error registering EGAVGA\n"); exit(1);
}
if (registerbgifont(small_font)<0) {
printf("Error registering small_font\n"); exit(1);
}
if (registerbgifont(sansserif_font)<0) {
printf("Error registering sansserif_font\n"); exit (1);
}
initgraph(&gdriver,&gmode,NULL);
if (gdriver<EGA) {
closegraph();
printf("Error: EGA or VGA required");
exit(1);
}
g_errorcode=graphresult();
if (g_errorcode!=grOk) {
printf("Graphics Error: %s\n", grapherrormsg(g_errorcode));
exit(1);
}
max_x=getmaxx();
max_y=getmaxy();
settextjustify(LEFT_TEXT,TOP_TEXT);
setbkcolor(EGA_BLUE);
}/* initialize() */
void getopts (int argc, char **argv) {
int i;
char *cp;
for (i=1;i<argc;i++) {
for (cp=argv[i];*cp;cp++) {
if (toupper(*cp)=='L') caps_only=0;
if (toupper(*cp)=='S') alnum_only=0;
}
}
}/* getopts() */
void copyright_license () {
int p,q;
setcolor(EGA_LIGHTRED);
settextstyle(SMALL_FONT,HORIZ_DIR,4);
p=(max_x-textwidth(copyright))/2;
outtextxy(p,0,copyright);
q=textheight(copyright);
p=(max_x-textwidth(address))/2;
outtextxy(p,q,address);
q+=textheight(address);
p=(max_x-textwidth(license))/2;
outtextxy(p,q,license);
}/* copyright_license() */
void intro_song () {
double note;
int i,p,q;
char alpha[2]={0,0};
setcolor(EGA_LIGHTCYAN);
delay(1);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,5);
p=(max_x-textwidth(lines[0]))/2;
q=textheight(lines[0])*3;
moveto(p,q/3);
outtext(lines[0]);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,7);
p=(max_x-textwidth(lines[1]))/2;
moveto(p,q);
q=q+textheight(lines[1])*3/2;
p=(max_x-textwidth(lines[2]))/2;
for (i=0;i<26;i++) {
if (i==13) moveto(p,q);
note=freq[song[i]];
sound((int)(note*2));
delay(12);
sound((int)note);
alpha[0]='A'+i;
setcolor(EGA_LIGHTBLUE+random(7));
outtext(alpha);
delay(len[i]*LEN-20);
nosound();
delay(20);
if (i==24) { /* Puts in a beat for "and" */
sound((int)(note*2));
delay(12);
sound((int)note);
delay(len[i]*LEN-20);
nosound();
delay(20);
}
}
q=q+textheight(lines[2])*2;
setcolor(EGA_LIGHTMAGENTA);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4);
p=(max_x-textwidth(lines[3]))/2;
moveto(p,q);
q=q+textheight(lines[3])*3/2;
p=(max_x-textwidth(lines[4]))/2;
for (i=0;i<16;i++) {
if (i==7) moveto(p,q);
note=freq[song[i]];
if(i!=12 && i!=14) {
sound((int)(note*2.));
delay(12);
}
sound((int)note);
outtext(end_song[i]);
delay(len[i]*LEN-20);
if (i!=11 && i!=13) nosound();
delay(20);
}
outtext("?");
delay(800);
}/* intro_song() */
void put_exit_msg () {
static char *exit_msg[2]= {
"Press a key to show a letter and play a note.",
"Press Control-Z to exit."
};
int p,q,r;
while(kbhit())getch(); /* clear keyboard buffer */
settextstyle(SMALL_FONT,HORIZ_DIR,5);
r=q=textheight(exit_msg[0])
+textheight(exit_msg[1]);
setviewport(0,0,max_x,r*3/2,0);
setcolor(EGA_WHITE);
p=(max_x-textwidth(exit_msg[0]))/2;
outtextxy(p,0,exit_msg[0]);
p=(max_x-textwidth(exit_msg[1]))/2;
q=textheight(exit_msg[0]);
outtextxy(p,q,exit_msg[1]);
setcolor(EGA_RED);
line(0,r*5/4,max_x,r*5/4);
setviewport(0,r*3/2,max_x,max_y,1);
}/* put_exit_msg() */
void do_letters () {
int c,i,j,k,p,q,r,s;
unsigned int byte_size;
char far *image;
char in[]={0,0};
double note;
struct viewporttype viewset,port1,port2;
char buffer[64];
buffer[0]=0;
setcolor(EGA_YELLOW);
getviewsettings((struct viewporttype far *)&viewset);
j=(viewset.bottom-viewset.top)*2/5;
port1.left=port2.left=0;
port1.right=port2.right=max_x;
port1.clip=port2.clip=1;
port1.top=viewset.top;
port1.bottom=viewset.top+(viewset.bottom-viewset.top)/2;
port2.top=port1.bottom+1;
port2.bottom=viewset.bottom;
clearviewport();
for (i=40;;i--) {
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,i);
if(textheight((char far *)"X")<j) break;
} /* this sets the text height through run-time test */
setport(port1);
while ((c=getch()) != 26) {
if (c==0) { /* extended keystrokes are ignored */
c=getch();
twirp();
continue;
}
if (caps_only) in[0]=toupper(c);
else in[0]=c;
if ((alnum_only && !(isalnum(c)))
&& !(isspace(c))) {
twirp();
continue;
}
if (isalpha(c)) {
i=toupper(c)-'A';
j=song[i];
} else if (isdigit(c)) j=scale[c=='0'?16:c-'0'+6];
else j=scale[random(8)];
note=freq[j];
sound((int)(note*4.));
delay(12);
sound((int)(note*2.));
delay(25);
sound((int)note);
s=0;
strcat(buffer,in);
if ((isspace(c)&&(c!=' '))||(textwidth(buffer)>=max_x)) {
getviewsettings(&viewset);
if (viewset.top==port1.top) {
setport(port2);
strcpy(buffer, in);
}
else {
s=1;
setport(port1);
clearviewport();
for(r=0;buffer[r];r++) ; /* loop through to end */
buffer[r-1]=0;
outtext(buffer);
setport(port2);
strcpy(buffer,in);
}
}
if (s&&(isspace(c))) {
buffer[0]=0;
clearviewport();
} else {
clearviewport();
outtext(buffer);
}
if (!kbhit()) delay(300);
nosound();
}
}/* do_letters() */
void twirp () {
sound((int)MIDDLE_C*8);
delay(6);
sound((int)MIDDLE_C*4);
delay(12);
sound((int)MIDDLE_C*2);
delay(50);
sound((int)MIDDLE_C*4);
delay(3);
sound((int)MIDDLE_C*2);
delay(50);
sound((int)MIDDLE_C*4);
delay(3);
nosound();
}/* twirp() */